const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const config = require("./src/config.json")

module.exports = [
    {
        name: 'web',
        mode: 'development',
        entry: "./src/web/index.js",
        output: {
            filename: 'static/index.js',
            path: path.resolve(__dirname, 'dist')
        },
        plugins: [
            new HtmlWebpackPlugin({
                title: '简单演示',
                filename: 'static/index.html'
            }),
        ],
        devtool: 'inline-source-map',
        devServer: {
            contentBase: './dist/static',
            proxy: {
                "/": {
                    target: "http://localhost:" + config.port,
                    bypass: (req, res, proxyOptions) => {
                        if (req.headers.accept.indexOf('application') !== -1 && req.url != '/') {
                            console.log(`proxy url: ${req.url}`)
                            return null;
                        }
                        return req.url;
                    }
                }
            },
            port: 8000
        },
    },
    {
        name: "server",
        target: 'node',
        entry: "./src/server/index.js",
        output: {
            filename: 'index.js',
            path: path.resolve(__dirname, 'dist')
        }
    }
];